class Solution:

    def findMedianSortedArrays(self, nums1, nums2) -> float:
        all_len = len(nums1) + len(nums2)
        med_i = int(all_len / 2 + 0.5)
        med = []
        n1_i = 0
        n2_i = 0
        while True:
            if n1_i >= len(nums1) or (n2_i < len(nums2) and nums1[n1_i] > nums2[n2_i]):
                n2_i += 1
                if n1_i + n2_i >= med_i:
                    med.append(nums2[n2_i - 1])
                    if all_len % 2 != 0 or len(med) > 1:
                        return self.avg(med)
                    else:
                        continue
                continue

            n1_i += 1
            if n1_i + n2_i >= med_i:
                med.append(nums1[n1_i - 1])
                if all_len % 2 != 0 or len(med) > 1:
                    return self.avg(med)
                else:
                    continue
            continue

    def avg(self, nums):
        if len(nums) > 1:
            return (nums[0] + nums[1]) / 2
        return nums[0]

if __name__ == '__main__':
    s = Solution()
    nums1 = [1, 2, 5]
    nums2 = [1]
    r = s.findMedianSortedArrays(nums1, nums2)
    # r = s.findMedianSortedArraysByOne(nums1)
    print(r)
    # print(nums1[:-1])
